---
import Layout from '../layouts/Layout.astro'
import Header from '../components/Header.astro'
import Footer from '../components/Footer.astro'
import Generator from '../components/Generator'
import '../message.css'
import 'katex/dist/katex.min.css'
import 'highlight.js/styles/atom-one-dark.css'
---

<Layout title="ChatGPT API Demo">
  <main >
    <Header />
    <Generator client:load />
    <Footer />
  </main>
</Layout>

<script>
async function checkCurrentAuth() {
  const openId = getCookie('highEQ');
  localStorage.setItem('openId', openId)
  // const password = localStorage.getItem('pass')
  // const response = await fetch('/api/auth', {
  //   method: 'POST',
  //   headers: {
  //     'Content-Type': 'application/json',
  //   },
  //   body: JSON.stringify({
  //     pass: password,
  //   }),
  // })
  // const responseJson = await response.json()
  // if (responseJson.code !== 0)
  //   window.location.href = '/password'
}

function getCookie(name: string): string | null {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop()?.split(';').shift() || null;
  return null;
}


checkCurrentAuth()
</script>
